<template>
  <div>
    <!-- 搜索 -->
    <!-- 经销商配件管理费率维护及工时系数维护 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable ref="table" :columns="columns" :params="fetchParams" :fetchapi="fetchapi" :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange" :is-select-column="false">
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</multiuse-button>
        <multiuse-button type="primary" :click="exportFileBtn.bind()">导出</multiuse-button>
<!--        <multiuse-button size="small" type="primary"  :loading="exportLoading" :click="downloadTemplate.bind()">下载模板</multiuse-button>-->
<!--        <multiuse-button size="small" icon="el-icon-upload" :click="showImportFun.bind()" >导入</multiuse-button>-->
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <DealerList @close="close" @save="save"></DealerList>
    </BaseDialog>
    <BaseDialog :visible.sync="visibleAdd" :title="'配件类型维护新增'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <AddForm @close="closeAdd" @save="saveAdd"></AddForm>
    </BaseDialog>
    <BaseDialog :visible.sync="visibleEdit" :title="'配件类型维护编辑'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <EditForm @close="closeEdit" @save="saveEdit" :rowData="rowData"></EditForm>
    </BaseDialog>
    <BaseDialog :visible.sync="showImport" :closable="false" icon="el-icon-upload" title="导入" width="800px" destroyOnClose :containerStyle="{ height: 'calc(100% - 120px)', overflow: 'auto', paddingBottom: '60px' }">
      <importExcel @close="showImport = false" @importclose="editsave()" url="/api/cms_claimfac/rPSpMngLab/importExcel"/>
    </BaseDialog>
  </div>
</template>
<script>
// import { dictionary } from '@/utils/dictMixin';
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import { exportExcelFile } from '@/utils/index';
import AddForm from './AddForm.vue';
import EditForm from './EditForm.vue';
import { getListByPage, downloadModel,getListForExport,exporturl} from '@/api/claim/factory/PartType/index.js';
// import importOrderParameterModel from "./importOrderParameterModel.vue";
import importExcel from '@/pages/claimDemage/tools/importExcel.vue';

export default {
  // mixins: [dictionary],
  components: {
    DealerList,
    AddForm,
    EditForm,
    importExcel
  },
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      rowData: null,
      infoId: null,
      showImport: false,
      fetchapi: getListByPage,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      dialogTitle: '选择经销商',
      visibleAdd: false,
      exportLoading: false,
      visibleEdit: false
    };
  },
  created() {
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    close(){
      this.visible = false;
    },
    chooseOrderNo() {
      this.visible = true;
    },
    save(obj) {
      this.topFilterInit.find(x => x.fieldName == 'dealerCode').initialValue = obj[0].dealerCode;
      this.visible = false;
    },
    add() {
      this.visibleAdd = true;
    },
    edit() {
      this.visibleEdit = true;
    },
    closeAdd() {
      this.visibleAdd = false;
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    },
    emitFun(val) {
      this.rowData = val;
      this.visibleEdit = true;
    },
    closeEdit() {
      this.visibleEdit = false;
    },
    saveEdit() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
    // Excel更新导入
    showImportFun() {
      this.showImport = true;
    },
    //下载模板
    downloadTemplate() {
      this.$confirm('此操作将下载excel模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.exportLoading = true;
        downloadModel().then(res => {
          exportExcelFile(res.data, ' 经销商配件管理费率维护及工时系数维护导入模板');
          this.exportLoading = false;
        });
      });
    },
    // 导出
   async exportFileBtn() {
      let json = Object.assign({}, { CODE: 'CODE_00000125' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
    },
    editsave(){
      this.showImport = false;
      this.fetchParams = {...this.fetchParams};
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'INPUT',
          label: '类型代码',
          fieldName: 'code',
          placeholder: '请输入类型代码...',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '类型名称',
          fieldName: 'name',
          placeholder: '请输入类型名称...',
          initialValue: '',
        },
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button size="mini" type="text" onClick={() => this.emitFun(props.row)}>编辑</multiuse-button>
              </div>
            );
          }
        },
        {title: '类型代码', dataIndex: 'codes', sorter: true},
        {title: '类型名称', dataIndex: 'name', sorter: true},
        {title: '创建人', dataIndex: 'createdByStr', sorter: true},
        {title: '创建时间', dataIndex: 'createdAt', sorter: true, width: 140},
        {title: '修改人', dataIndex: 'updatedByStr', sorter: true},
        {title: '修改时间', dataIndex: 'updatedAt', sorter: true, width: 140}
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
